package com.interrobang.gui;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainPanel extends JPanel 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6616679479413364922L;
	private Image background;
	private boolean menuActive;
	private boolean addActive;
	private boolean viewActive;
	private boolean gameActive;
	private MenuPanel menu;
	private AddAnimePanel addAnime;
	private ViewAnimePanel viewAnime;
	private JFrame frame;
	private GamePanel game;
	
	public MainPanel(JFrame frame)
	{
		
		menuActive = true;
		this.frame = frame;
		
		try {
			background = ImageIO.read(new File("Graphics/Main BackGround.jpg"));
		} catch (IOException e) {e.printStackTrace();}
		menu = new MenuPanel(this);
		addAnime = new AddAnimePanel(this);
		viewAnime = new ViewAnimePanel(this);
		game = new GamePanel(this);
		add(game);
		add(menu);
		add(addAnime);
		add(viewAnime);
		update();
		}
	
	
	public void paint(Graphics g)
	{
		super.paint(g);
		g.drawImage(background, 0, 0, frame.getWidth(), frame.getHeight(), null);
		for (int i = 0; i < this.getComponentCount(); i++)
	     {
	          this.getComponent(i).repaint();
	     }
	}
	
	public void update()
	{
		removeAll();
		if(gameActive)
		{
			add(game);
			game.update();
		}
		if(menuActive)
		{
			add(menu);
		}
		else if(addActive)
		{
			add(addAnime);
			addAnime.update();
		}
		else if(viewActive)
		{
			add(viewAnime);
			viewAnime.update();
			viewAnime.setVisible(true);
		}
		updateUI();
	}

	/**
	 * @return the background
	 */
	public Image getImage() {
		return background;
	}

	/**
	 * @param background the background to set
	 */
	public void setBackground(Image background) {
		this.background = background;
	}

	/**
	 * @return the menuActive
	 */
	public boolean isMenuActive() {
		return menuActive;
	}

	/**
	 * @param menuActive the menuActive to set
	 */
	public void setMenuActive(boolean menuActive) {
		this.menuActive = menuActive;
	}

	/**
	 * @return the addActive
	 */
	public boolean isAddActive() {
		return addActive;
	}

	/**
	 * @param addActive the addActive to set
	 */
	public void setAddActive(boolean addActive) {
		this.addActive = addActive;
	}

	/**
	 * @return the viewActive
	 */
	public boolean isViewActive() {
		return viewActive;
	}

	/**
	 * @param viewActive the viewActive to set
	 */
	public void setViewActive(boolean viewActive) {
		this.viewActive = viewActive;
	}

	/**
	 * @return the gameActive
	 */
	public boolean isGameActive() {
		return gameActive;
	}

	/**
	 * @param gameActive the gameActive to set
	 */
	public void setGameActive(boolean gameActive) {
		this.gameActive = gameActive;
	}

	/**
	 * @return the menu
	 */
	public MenuPanel getMenu() {
		return menu;
	}

	/**
	 * @param menu the menu to set
	 */
	public void setMenu(MenuPanel menu) {
		this.menu = menu;
	}

	/**
	 * @return the addAnime
	 */
	public AddAnimePanel getAddAnime() {
		return addAnime;
	}

	/**
	 * @param addAnime the addAnime to set
	 */
	public void setAddAnime(AddAnimePanel addAnime) {
		this.addAnime = addAnime;
	}

	/**
	 * @return the frame
	 */
	public JFrame getFrame() {
		return frame;
	}

	/**
	 * @param frame the frame to set
	 */
	public void setFrame(JFrame frame) {
		this.frame = frame;
	}

}
